class DNode(object):
    def __init__(self,item):
        self.item = item
        self.pre = None
        self.next = None

class DLinkList(object):
    def __init__(self):
        self.head = None
    def isEmpty(self):
        return self.head == None
    def length(self):
        cur = self.head
        count = 0
        while cur != None:
            count += 1
            cur = cur.next
        return  count
    def travel(self):
        if self.head == None:
            print("")
        cur = self.head
        while cur != None:
            print(cur.item)
            cur = cur.next
    def add(self,item):
        node = DNode(item)
        if self.head == None:
            self.head = node
            node.pre = None
        else:
            node.next = self.head
            self.head.pre = node
            self.head = node
    def append(self,item):
        node = DNode
        if self.head == None:
            self.head = node
        else:
            cur = self.head
            while cur.next != None:
                cur = cur.next
            cur.next = node
            node.pre = cur
    def insert(self,pos,item):
        if pos <= 0:
            self.add(item)
        elif pos >= (self.length() -1):
            self.append(item)
        else:
            node = DNode(item)
            cur = self.head
            count = 0
            while count < (pos -1):
                count += 1
                cur = cur.next
            node.pre = cur
            node.next= cur.next
            cur.next.pre = node
            cur.next = node

    def remove(self,item):#删除元素
        if self.isEmpty():
            return
        else:
            cur = self.head
            if cur.item == item :
                if cur.next == None:
                    self.head = None
                else:
                    self.head = cur.next
                    cur.next.pre = None
                return
            while cur != None:
                if cur.item == item:
                    cur.pre.next = cur.next
                    cur.next.pre = cur.pre
                    break
                cur = cur.next
    def search(self,item):
        cur = self.head
        while cur !=None:
            if cur.item == item:
                return True
            cur = cur.next
        return False